import { createRouter, createWebHistory } from 'vue-router'
import { useStore } from '@/stores'
import { Message } from '@arco-design/web-vue'

declare module 'vue-router' {
    interface RouteMeta {
        title?: string
        isLogin?: boolean
        power?: string[]
    }
}
const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        {
            path: '/login',
            name: 'login',
            component: () => import('../views/login/index.vue'),
        },

        {
            path: '/',
            name: 'admin',
            meta: {
                title: '后台管理',
                isLogin: true,
            },
            component: () => import('../views/admin/index.vue'),
            children: [
                {
                    path: '',
                    name: 'dashboard',
                    meta: {
                        title: '仪表盘',
                    },
                    component: () =>
                        import('../views/admin/dashboard/index.vue'),
                },
                /**首页下 */
                {
                    path: 'home',
                    name: 'home',
                    meta: {
                        title: '首页',
                    },
                    children: [
                        {
                            path: 'faculty',
                            name: 'faculty',
                            meta: {
                                title: '师资力量',
                            },
                            component: () =>
                                import('../views/admin/home/faculty.vue'),
                        },
                        {
                            path: 'student_tyle',
                            name: 'student_tyle',
                            meta: {
                                title: '学生风采',
                            },
                            component: () =>
                                import('../views/admin/home/student_tyle.vue'),
                        },
                        {
                            path: 'zt_real_info',
                            name: 'zt_real_info',
                            meta: {
                                title: '振涛实讯',
                            },
                            component: () =>
                                import('../views/admin/home/zt_real_info.vue'),
                        },
                        {
                            path: 'header_change',
                            name: 'header_change',
                            meta: {
                                title: '头图更改',
                            },
                            component: () =>
                                import('../views/admin/home/header_change.vue'),
                        },
                    ],
                },
                /**学院概况 */
                {
                    path: 'college_profile',
                    name: 'college_profile',
                    meta: {
                        title: '学院概况',
                    },
                    children: [
                        {
                            path: 'geographic_position',
                            name: 'geographic_position',
                            meta: {
                                title: '地理位置',
                            },
                            component: () =>
                                import(
                                    '../views/admin/college_profile/geographic_position.vue'
                                ),
                        },
                        {
                            path: 'zt_big_event',
                            name: 'zt_big_event',
                            meta: {
                                title: '振涛大事记',
                            },
                            component: () =>
                                import(
                                    '../views/admin/college_profile/zt_big_event.vue'
                                ),
                        },
                        {
                            path: 'cooperative_enterprise',
                            name: 'cooperative_enterprise',
                            meta: {
                                title: '合作企业',
                            },
                            component: () =>
                                import(
                                    '../views/admin/college_profile/cooperative_enterprise.vue'
                                ),
                        },
                    ],
                },
                /**热门专业 */
                {
                    path: 'popular_major',
                    name: 'popular_major',
                    meta: {
                        title: '热门专业',
                    },
                    children: [
                        {
                            path: 'artificial_intelligence',
                            name: 'artificial_intelligence',
                            meta: {
                                title: '人工智能',
                            },
                            component: () =>
                                import(
                                    '../views/admin/popular_major/artificial_intelligence.vue'
                                ),
                        },
                        {
                            path: 'media',
                            name: 'media',
                            meta: {
                                title: '振涛大事记',
                            },
                            component: () =>
                                import(
                                    '../views/admin/popular_major/media.vue'
                                ),
                        },
                        {
                            path: 'website_engineering',
                            name: 'website_engineering',
                            meta: {
                                title: '合作企业',
                            },
                            component: () =>
                                import(
                                    '../views/admin/popular_major/website_engineering.vue'
                                ),
                        },
                        {
                            path: 'metaverse',
                            name: 'metaverse',
                            meta: {
                                title: '元宇宙',
                            },
                            component: () =>
                                import(
                                    '../views/admin/popular_major/metaverse.vue'
                                ),
                        },
                        {
                            path: 'big_data',
                            name: 'big_data',
                            meta: {
                                title: '大数据',
                            },
                            component: () =>
                                import(
                                    '../views/admin/popular_major/big_data.vue'
                                ),
                        },
                        {
                            path: 'cloud_computing',
                            name: 'cloud_computing',
                            meta: {
                                title: '云计算',
                            },
                            component: () =>
                                import(
                                    '../views/admin/popular_major/cloud_computing.vue'
                                ),
                        },
                    ],
                },
                /**特色优势 */
                {
                    path: 'characteristic_advantage',
                    name: 'characteristic_advantage',
                    meta: {
                        title: '特色优势',
                    },
                    children: [
                        {
                            path: 'cjrh',
                            name: 'cjrh',
                            meta: {
                                title: '产教融合',
                            },
                            component: () =>
                                import(
                                    '../views/admin/characteristic_advantage/cjrh.vue'
                                ),
                        },
                        {
                            path: 'enterprise_culture',
                            name: 'enterprise_culture',
                            meta: {
                                title: '企业文化',
                            },
                            component: () =>
                                import(
                                    '../views/admin/characteristic_advantage/enterprise_culture.vue'
                                ),
                        },
                        {
                            path: 'real_project',
                            name: 'real_project',
                            meta: {
                                title: '真实项目',
                            },
                            component: () =>
                                import(
                                    '../views/admin/characteristic_advantage/real_project.vue'
                                ),
                        },
                    ],
                },
                /**校园环境 */
                {
                    path: 'campus_environment',
                    name: 'campus_environment',
                    meta: {
                        title: '校园环境',
                    },
                    children: [
                        {
                            path: 'Intellectual_growth',
                            name: 'Intellectual_growth',
                            meta: {
                                title: '智慧成长',
                            },
                            component: () =>
                                import(
                                    '../views/admin/campus_environment/Intellectual_growth.vue'
                                ),
                        },
                        {
                            path: 'healthy_diet',
                            name: 'healthy_diet',
                            meta: {
                                title: '健康饮食',
                            },
                            component: () =>
                                import(
                                    '../views/admin/campus_environment/healthy_diet.vue'
                                ),
                        },
                        {
                            path: 'student_home',
                            name: 'student_home',
                            meta: {
                                title: '学生之家',
                            },
                            component: () =>
                                import(
                                    '../views/admin/campus_environment/student_home.vue'
                                ),
                        },
                    ],
                },
                /**联系我们 */
                {
                    path: 'contact_us',
                    name: 'contact_us',
                    meta: {
                        title: '联系我们',
                    },
                    children: [
                        {
                            path: 'enroll_student',
                            name: 'enroll_student',
                            meta: {
                                title: '招生',
                            },
                            component: () =>
                                import(
                                    '../views/admin/contact_us/enroll_student.vue'
                                ),
                        },
                        {
                            path: 'recruitment_position',
                            name: 'recruitment_position',
                            meta: {
                                title: '招聘岗位',
                            },
                            component: () =>
                                import(
                                    '../views/admin/contact_us/recruitment_position.vue'
                                ),
                        },
                        {
                            path: 'contact',
                            name: 'contact',
                            meta: {
                                title: '联系',
                            },
                            component: () =>
                                import('../views/admin/contact_us/contact.vue'),
                        },
                    ],
                },
                /**学校地址 */
                {
                    path: 'school_address',
                    name: 'school_address',
                    meta: {
                        title: '学校地址',
                    },
                    component: () =>
                        import('../views/admin/school_address/index.vue'),
                },
                {
                    path: '403',
                    name: '403',
                    meta: {
                        title: '403',
                    },
                    component: () => import('../views/error/403.vue'),
                },
                {
                    path: 'user_center',
                    name: 'user_center',
                    meta: {
                        title: '个人中心',
                    },
                    children: [
                        {
                            path: 'user_info',
                            name: 'user_info',
                            meta: {
                                title: '我的信息',
                            },
                            component: () =>
                                import(
                                    '../views/admin/user_center/user_info.vue'
                                ),
                        },
                    ],
                },
                {
                    path: 'users',
                    name: 'users',
                    meta: {
                        title: '用户管理',
                        power: ['admin'],
                    },
                    children: [
                        {
                            path: 'user_list',
                            name: 'user_list',
                            meta: {
                                title: '用户列表',
                            },
                            component: () =>
                                import('../views/admin/users/user_list.vue'),
                        },
                    ],
                },
                {
                    path: 'system',
                    name: 'system',
                    meta: {
                        title: '系统管理',
                        power: ['admin'],
                    },
                    children: [
                        {
                            path: 'menu_list',
                            name: 'menu_list',
                            meta: {
                                title: '菜单列表',
                            },
                            component: () =>
                                import('../views/admin/system/menu_list.vue'),
                        },
                        {
                            path: 'log_list',
                            name: 'log_list',
                            meta: {
                                title: '系统日志',
                            },
                            component: () =>
                                import('../views/admin/system/log_list.vue'),
                        },
                    ],
                },
            ],
        },
    ],
})

//路由守卫
// router.beforeEach((to, from, next) => {
//     const store = useStore()
//
//     const role_name = store.userInfo.role_name
//
//     if (to.meta.isLogin && !store.isLogin) {
//         Message.warning('请先登录')
//         next('/login')
//         return
//     }
//
//     if (to.meta?.power && !to.meta.power?.includes(role_name)) {
//         Message.warning('权限不足')
//         next({ name: '403' })
//         return
//     }
//
//     next()
// })

export default router
